/* This program is free software. It comes without any warranty, to
 * the extent permitted by applicable law. You can redistribute it
 * and/or modify it under the terms of the Do What The Fuck You Want
 * To Public License, Version 2, as published by Sam Hocevar. See
 * http://sam.zoy.org/wtfpl/COPYING for more details. */ 
package de.rockon.fuzzy.controller.operators.raw;

import de.rockon.fuzzy.controller.operators.AbstractOperator;
import de.rockon.fuzzy.controller.util.factories.IconFactory;

/**
 * UND Operator welcher auf der min() Funktion beruht
 */
public class AndMinOperator extends AbstractOperator<Double> {

	@Override
	public Double execute() {
		if (operands.isEmpty()) {
			return -1.0;
		}

		if (operands.size() == 1) {
			return operands.peek();
		}

		while (operands.size() > 1) {
			double op1 = operands.poll();
			double op2 = operands.poll();

			double result = op1 < op2 ? op1 : op2;
			operands.offer(result);
		}
		return operands.poll();
	}

	@Override
	public String getDescription() {
		return "Performs the AndMin-Operation";
	}

	@Override
	public String getIcon() {
		return IconFactory.ICON_RULE_AND;
	}

	@Override
	public String toString() {
		return "AND_MIN";
	}
}